package com.sky.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sky.service.UserService;

//点击邮箱的激活连接修改用户激活状态
public class ActiveCodeServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
   //根据指定的激活码去激活对应的状态  
		PrintWriter printWriter = response.getWriter();
		//得到激活码，
		//1.获取请求参数
		String activeCode = request.getParameter("activeCode");
		//2.处理业务逻辑，激活验证码
		 UserService userService=new UserService();
		 try {
			boolean isFlag =  userService.activeCode(activeCode);
			//3.分发转向
			if (isFlag) {
				//邮箱激活成功,跳转到登录页面
				request.setAttribute("msg", "激活成功，请登录");
				request.getRequestDispatcher("login.jsp").forward(request, response);
			}else{
				//邮箱激活失败
				printWriter.write("邮箱激活失败,请重新激活");
				System.out.println("邮箱激活失败,请重新激活");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			//邮箱激活失败
			printWriter.write("邮箱激活失败,请重新激活");
			System.out.println("邮箱激活失败,请重新激活");
		}

		
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
